#!/usr/bin/env lua

local L = require "functional.list"

-- zip({1,2,3}, {4, 5, 6})   ->  {1, 4}, {2, 5}, {3, 6}

zip_res = L.zip({1,2,3}, {4, 5, 6})

assert(zip_res[1][1] == 1)
assert(zip_res[1][2] == 4)
assert(zip_res[2][1] == 2)
assert(zip_res[2][2] == 5)
assert(zip_res[3][1] == 3)
assert(zip_res[3][2] == 6)


function add(x,y) return x + y end

-- map(add, {1,2,3}, {10, 20, 30})     -> {11, 22, 33}

map_res = L.map(add, {1,2,3}, {10, 20, 30})

assert(map_res[1] == 11)
assert(map_res[2] == 22)
assert(map_res[3] == 33)

function is_equal (x, y) return x == y end

filter_res = L.filter(is_equal, {10, 22, 30, 44, 40}, {10, 20, 30, 40})

assert(filter_res[1][1] == 10)
assert(filter_res[1][2] == 10)
assert(filter_res[2][1] == 30)
assert(filter_res[2][2] == 30)

function is_less (x, y) return x < y end

filter_res = L.filter(is_less, {10, 20, 30, 40}, {10, 22, 33, 40})

assert(filter_res[1][1] == 20)
assert(filter_res[1][2] == 22)
assert(filter_res[2][1] == 30)
assert(filter_res[2][2] == 33)


print "All tests passed."
